package Top_Interview_Questions.Greedy;

/**
 * @Author: 吕庆龙
 * @Date: 2020/1/19 17:24
 * <p>
 *
 */
public class _0122 {


    /**
     * 解析:
     * https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii
     * /solution/tan-xin-suan-fa-by-liweiwei1419-2/
     *
     * 贪心解释的比较好
     */
    public int maxProfit(int[] prices) {
        int res = 0;
        int len = prices.length;
        for (int i = 0; i < len - 1; i++) {
            int diff = prices[i + 1] - prices[i];
            if (diff > 0)
                res += diff;
        }
        return res;
    }


}
